host = "http://leet.arc.rpi.edu:7900/";
frequency = 5 * 60 * 1000; /* 5 minutes */

$(document).ready(function(){
	$("#rtfm").click(function () { 
    	$(".normal").fadeOut(2000, function () {
			$(".normal").fadeIn(2000);
		}); 
	});
});

function update_log(text) {
    eval(text).forEach(function(log) {
        elm = document.getElementById('count-' + log[0]);
        if (elm)
            elm.innerHTML = log[1];
    });
}

function inc_log(text) {
    eval(text).forEach(function(log) {
        elm = document.getElementById('count-' + log[0]);
        if (elm)
            elm.innerHTML = parseInt(elm.innerHTML) + log[1];
    });
}

function ifready(func) {
    return function() {
        if (this.readyState == 4) func(this.responseText);
    }
}

function add_to(name) {
    xhr = new XMLHttpRequest();
    xhr.onreadystatechange = ifready(inc_log);
    xhr.open("get", host + "json/log/" + name);
    xhr.send();
}

function update() {
    xhr = new XMLHttpRequest();
    xhr.onreadystatechange = ifready(update_log);
    xhr.open("get", host + "json/log/");
    xhr.send();
}

function init() {
    setInterval("update()", frequency);
    alert("Mimo Loaded: Jump around, jump around.");
}